package com.hy.controller;
/**
 * @版本 1.0
 * @作者 坏银
 * @时间 2021/10/28 15:51
 * @作用 向数据库里面添加操作
 */

import com.hy.pojo.*;
import com.hy.service.impl.*;
import com.hy.util.GetFormula;
import com.hy.vo.Formula;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class addSequence {

    @Resource
    private SequenceServiceImpl sequenceService;
    @Resource
    private SequenceAdditionServiceImpl sequenceAdditionService;
    @Resource
    private SequenceDivisionServiceImpl sequenceDivisionService;
    @Resource
    private SequenceMultiplicationServiceImpl sequenceMultiplicationService;
    @Resource
    private SequenceSubtractionServiceImpl sequenceSubtractionService;


    /**
     * @作用 向数据库中添加随机数据
     */
    @GetMapping("/addRandom")
    public String addRandom() {
        Sequence sequence = new Sequence();
        for (int i = 1; i <= 5000; i++) {
            Formula formula = GetFormula.toGetFormula();
            sequence.setId(i);
            sequence.setForward(formula.getForward());
            sequence.setSymbol(formula.getSymbol());
            sequence.setBehind(formula.getBehind());
            sequence.setAnswer(formula.getAnswer());
            sequenceService.save(sequence);
        }
        log.info("随机数据后端添加成功");
        return "success";
    }

    /**
     * @作用 向数据库中添加加法数据
     */
    @GetMapping("/addAddition")
    public String addAddition() {
        SequenceAddition sequence = new SequenceAddition();
        for (int i = 1; i <= 5000; i++) {
            Formula formula = GetFormula.toGetAdditionFormula();
            sequence.setId(i);
            sequence.setForward(formula.getForward());
            sequence.setSymbol(formula.getSymbol());
            sequence.setBehind(formula.getBehind());
            sequence.setAnswer(formula.getAnswer());
            sequenceAdditionService.save(sequence);
        }
        log.info("加法数据后端添加成功");
        return "success";
    }

    /**
     * @作用 向数据库中添加除法数据
     */
    @GetMapping("/addDivision")
    public String addDivision() {
        SequenceDivision sequence = new SequenceDivision();
        for (int i = 1; i <= 5000; i++) {
            Formula formula = GetFormula.toGetDivisionFormula();
            sequence.setId(i);
            sequence.setForward(formula.getForward());
            sequence.setSymbol(formula.getSymbol());
            sequence.setBehind(formula.getBehind());
            sequence.setAnswer(formula.getAnswer());
            sequenceDivisionService.save(sequence);
        }
        log.info("除法数据后端添加成功");
        return "success";
    }

    /**
     * @作用 向数据库中添加乘法数据
     */
    @GetMapping("/addMultiplication")
    public String addMultiplication() {
        SequenceMultiplication sequence = new SequenceMultiplication();
        for (int i = 1; i <= 5000; i++) {
            Formula formula = GetFormula.toGetMultiplicationFormula();
            sequence.setId(i);
            sequence.setForward(formula.getForward());
            sequence.setSymbol(formula.getSymbol());
            sequence.setBehind(formula.getBehind());
            sequence.setAnswer(formula.getAnswer());
            sequenceMultiplicationService.save(sequence);
        }
        log.info("乘法数据后端添加成功");
        return "success";
    }

    /**
     * @作用 向数据库中添加减法数据
     */
    @GetMapping("/addSubtraction")
    public String addSubtraction() {
        SequenceSubtraction sequence = new SequenceSubtraction();
        for (int i = 1; i <= 5000; i++) {
            Formula formula = GetFormula.toGetSubtractionFormula();
            sequence.setId(i);
            sequence.setForward(formula.getForward());
            sequence.setSymbol(formula.getSymbol());
            sequence.setBehind(formula.getBehind());
            sequence.setAnswer(formula.getAnswer());
            sequenceSubtractionService.save(sequence);
        }
        log.info("减法数据后端添加成功");
        return "success";
    }
}
